package com.example.musicgui.view;
import com.example.musicgui.controller.UserController;
import com.example.musicgui.model.ResponseBodyMessage;
import com.example.musicgui.model.User;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.awt.*;
import java.util.List;

public class Index {
    private Stage stage;
    private Scene scene;
    private Button[] buttons;
    private Button checkButton;
    private BorderPane mainPane;
    private BorderPane topPane;
    private BorderPane bottomPane;
    private VBox rightMenu,leftMenu;
    private Integer userId;
    private HBox searchBox;
    private VBox dataBox;
    private TextField search;
    private Button searchButton;

    public Index(Stage stage) {
        this.stage = stage;
        this.topPane = new BorderPane();
        getData();
        this.bottomPane = new BorderPane();
        bottomPane.setMaxHeight(150);
        this.mainPane = new BorderPane();
        bottomPane.setStyle(Styles.BACKGROUND_TWO);
        mainPane.setTop(topPane);
        mainPane.setBottom(bottomPane);
        mainPane.setStyle(Styles.BACKGROUND_ONE);
        scene = new Scene(mainPane, 1680, 1050);
        getData();
    }



    public void show(Integer userId) {
        stage.setScene(scene);
        stage.setTitle("声匠");
        System.out.println("id" + userId);
        this.userId = userId;
        stage.show();
        stage.centerOnScreen();
    }
    private void getButton(VBox leftMenu) {
        leftMenu.setPrefWidth(300); // 设置宽度为 300
        this.buttons = new Button[4];
        String[] str = {"推    荐","喜    欢","最近播放","自建歌单"};
        for (int i = 0; i < 4; i++) {
            HBox center = new HBox();
            center.setAlignment(Pos.CENTER);
            center.setMaxWidth(300);
            buttons[i] = new Button(str[i]);
            buttons[i].setStyle(Styles.BUTTON_THREE);
            center.getChildren().add(buttons[i]);
            leftMenu.getChildren().add(center);
        }
        checkButton = buttons[0];
        checkButton.setStyle(Styles.BUTTON_FOUR);
        buttonActions();
    }
    private void buttonActions() {
        this.buttons[0].setOnAction(event -> {
            System.out.println("推荐");
            orCheckButton();
            checkButton = buttons[0];
            checkButton.setStyle(Styles.BUTTON_FOUR);
            getRanking();
        });
        this.buttons[1].setOnAction(event ->{
            System.out.println("喜欢");
            orCheckButton();
            checkButton = buttons[1];
            checkButton.setStyle(Styles.BUTTON_FOUR);
        });
        this.buttons[2].setOnAction(event ->{
            System.out.println("最近播放");
            orCheckButton();
            checkButton = buttons[2];
            checkButton.setStyle(Styles.BUTTON_FOUR);
        });
        this.buttons[3].setOnAction(event ->{
            System.out.println("自建歌单");
            orCheckButton();
            checkButton = buttons[3];
            checkButton.setStyle(Styles.BUTTON_FOUR);
        });
    }
    private void orCheckButton() {
        checkButton.setStyle(Styles.BUTTON_THREE);
    }
    private void getData() {
        this.leftMenu = new VBox();
        getButton(leftMenu);
        this.leftMenu.setStyle(Styles.BACKGROUND_TWO);
        this.rightMenu = new VBox();
        this.rightMenu.setStyle(Styles.BACKGROUND_THREE);
        getSearchBox();
        getRanking();
        topPane.setLeft(leftMenu);
        topPane.setRight(rightMenu);

    }

    private void getSearchBox() {
        searchBox = new HBox();
        search = new TextField();
        search.setStyle(Styles.TEXTFIELD_TWO);
        searchButton = new Button("搜索");
        searchButton.setStyle(Styles.BUTTON_FIVE);
        searchBox.getChildren().add(search);
        searchBox.getChildren().add(searchButton);
        searchBox.setMaxHeight(100);
        searchBox.setStyle(Styles.MARGIN_ONE);
        rightMenu.getChildren().add(searchBox);
    }

    private void getRanking() {
        dataBox = new VBox();
        dataBox.getChildren().add(new RankingMusic().getvBox());
        rightMenu.getChildren().add(dataBox);
    }
}